/*
 *
 * @ClassName: XMLHandler.as
 * @Classdescription:
 * @author vargaf
 * @Date: 09.05.2008
 * @Mod:
 * @eMail: francis.varga@juwimm.com
 *
 */

import com.xfactorstudio.xml.xpath.*;
import engine.MyMenu;

class utils.XMLHandler extends XML{
	
	public static var xmlArray:Array						= null;
	public static var xmlObject:Object						= null;
	
	public function XMLHandler(xmlPath:String){
		
		trace("=== XMLHandler ===");
		
		xmlPath					= xmlPath || "data/xml/main/main.xml";
		
		xmlArray				= new Array();
		xmlObject				= new Object();
		
		loadXML(xmlPath);
		
	}
	
	public function loadXML(xmlPath:String){
		
		onLoad = function(success:Boolean){
			if(success){
				trace("XML to load Successfuly");
				myParser();
				Main.afterLoadXML();
			}else{
				trace("XML to load Error");
			}
		};
		
		load(xmlPath);
		
	}
	
	private function myParser():Void{
		
		var labelPath:String 				= "//all/menu/item/label";
		var swfPath:String					= "//all/menu/item/swfPath";
		var animationPath:String			= "//all/menu/item/animation";
		var xmlPath:String					= "//all/menu/item/xmlPath";
		
		xmlArray.label						= new Array();
		xmlArray.label						= XPath.selectNodesAsString(this, labelPath);
		xmlArray.swfPath					= new Array();
		xmlArray.swfPath					= XPath.selectNodesAsString(this, swfPath);
		xmlArray.animation					= new Array();
		xmlArray.animation					= XPath.selectNodesAsString(this, animationPath);
		
		for(var i:Number=0; i <= xmlArray.label.length - 1; i++){
			
			MyMenu.createMenu(xmlArray.label[i],xmlArray.swfPath[i]);
			
		}
		
	}
	
	public static function getXMLArray():Array{ return xmlArray; }
	public static function getXMLObject():Object{ return xmlObject; }
	
}